/*
 * Copyright 2017 JessYan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package me.jessyan.armscomponent.app.mvp.ui.holder;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.jess.arms.base.BaseHolder;

import butterknife.BindView;
import me.jessyan.armscomponent.app.R;
import me.jessyan.armscomponent.app.mvp.model.entity.Question;

/**
 * ================================================
 * 展示 {@link BaseHolder} 的用法
 * <p>
 * Created by JessYan on 9/4/16 12:56
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * ================================================
 */
public class QAQuestionItemHolder extends BaseHolder<Question> {

    @BindView(R.id.user_question_qu_contentAra)
    TextView user_question_qu_contentAra;
    @BindView(R.id.user_question_qu_answer)
    EditText user_question_qu_answer;


    public QAQuestionItemHolder(View itemView) {
        super(itemView);
    }

    @Override
    public void setData(Question data, int position) {
        //itemView 的 Context 就是 Activity, Glide 会自动处理并和该 Activity 的生命周期绑定
        user_question_qu_contentAra.setText(position+1+": "+data.getContentAra()+"");
        user_question_qu_answer.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String answer = s.toString();
                if(!TextUtils.isEmpty(answer)){
                    data.setAnswer(answer);
                }
            }
        });
    }

    @Override
    protected void onRelease() {
    }
}
